I am looking to read the permmisions from one item (in this case an attribute definition)and assign those permissions to another attribute. Has anyone a way of doing this? Probably involve converting a string to a Permission.
|
Re: Reading permissions from one item to another
You need to get the Access Records of Attr1, get the names and accesses, then apply them to Attr2. One of the 'nuances' is that there are two kinds of accesses for an attribute def: [1] access to the DEF (can the user re-define the attribute), and [2] access to the VALUES (can the user change the value of an object). The commands therefore have 'Def' or 'Val' suffixes to distinquish the two.
//********************************
Permission fPermisOf(AccessRec ar)
{ // Get the Permissions associated with the AccessRec.
Permission Permis = none()
if (null ar) return(Permis)
if (read(ar)) Permis = Permis | read
if (modify(ar)) Permis = Permis | modify
if (create(ar)) Permis = Permis | create
if (delete(ar)) Permis = Permis | delete
if (control(ar)) Permis = Permis | control
return(Permis)
} // end fPermisOf(ar)
Module mod = current
AttrDef ad1 = find(mod, "Attr1")
AttrDef ad2 = find(mod, "Attr2")
AccessRec ar1, ar2
Permission ps1
string Name
bool IsInherit1, IsInherit2
isAccessInheritedDef(mod, ar1, IsInherit1)
isAccessInheritedDef(mod, ar2, InInherit2)
if ( IsInherit1 and IsInherit2) then return. // Nothing to do
if ( IsInherit1 and !IsInherit2) then inheritedDef(mod, ad2); return // set Attr2 Inherited. Nothing else to do
if (!IsInherit1 and IsInherit2) then specificDef(mod, ad2) // Set Attr2 to specific. Proceed.
// At this point, Attr1 and Attr2 both have Specific access. Make Attr2 access same as Attr1
Skip skpAccess2 = createString() // Original accesses to Attr2.
// KEY and DATA both 'string' User/Group name
// Store Attr2's original Names
for ar2 in ad2 do // For values, this is "for ar2 in values(ad2) do"
{ Name = username(ar2)
put(skpAccess2, Name, Name)
}
// Give Attr2 same access records as Attr1
for ar1 in ad1 do
{ Name = username(ar1) // Name of this access
ps1 = fPermisOf(ar1) // Permissions for this access
setDef(mod, ad2, ps1, Name)
delete(skpAccess2, Name) // Delete this name from the old 2 list; ignore not-there error
}
// Delete residual Attr2 Accesses
for Name in skpAccess2 do
{ if (null Name)
{ // this is the default 'Everyone Else' acesses. Don't think its possible to get
// Here since Attr1 MUSt have a default access and it was removed from the skip
}
else unsetDef(mod, ad2, Name)
}
delete(skpAccess2)
|
Re: Reading permissions from one item to another |
Re: Reading permissions from one item to another SystemAdmin - Wed Nov 04 12:59:36 EST 2009 If you got something that worked, go ahead and post it.
|
Re: Reading permissions from one item to another llandale - Wed Nov 04 15:12:34 EST 2009
Permission fPermisOf(AccessRec ar) { // Get the Permissions associated with the AccessRec. Permission Permis = none() if (null ar) return(Permis) if (read(ar)) Permis = Permis | read if (modify(ar)) Permis = Permis | modify if (create(ar)) Permis = Permis | create if (delete(ar)) Permis = Permis | delete if (control(ar)) Permis = Permis | control return(Permis) // end fPermisOf(ar) } void setAttributeAccessRights(AttrDef adS, AttrDef adT) { AccessRec arS, arT Permission ps1 string Name bool IsInheritS, IsInheritT // For Attribute Definition :- isAccessInheritedDef(StandardModule, adS, IsInheritS) isAccessInheritedDef(TargetModule, adT, IsInheritT) if ( IsInheritS and IsInheritT) { // Nothing to do } else if ( IsInheritS and !IsInheritT) { inheritedDef(TargetModule, adT) // set Attr2 Inherited. Nothing else to do }else { if (!IsInheritS and IsInheritT) then specificDef(TargetModule, adT) // Set Attr2 to specific. Proceed. // At this point, Attr1 and Attr2 both have Specific access. Make Attr2 access same as Attr1 unsetAllDef(TargetModule, adT) // Clear out existing access rights // Give Attr2 same access records as Attr1 for arS in adS do { Name = username(arS) // Name of this access ps1 = fPermisOf(arS) // Permissions for this access if (!null Name) { setDef(TargetModule, adT, ps1, Name) } else { setDef(TargetModule, adT, ps1, null) } } } } Thanks for your help Louie TheRat (Otherwise known as Pete) |